// pages/video/video.js
const app = getApp();
const DB = wx.cloud.database()
var that;
var util = require('../../utils/util');
var yun_file_id_arr = [];
var text = ''
Page({

  dom(e) {
    var tempFilePaths = e.currentTarget.id
    wx.saveFile({
      tempFilePath: tempFilePaths,
      success(res) {
        const savedFilePath = res.savedFilePath
        wx.showToast({
          title: '下载成功',
        })
      }
    })
  },
  // 点击cover播放，其它视频结束
  videoPlay: function (e) {
    var _index = e.currentTarget.id
    this.setData({
      _index: _index
    })
    //停止正在播放的视频
    var videoContextPrev = wx.createVideoContext(this.data._index)
    videoContextPrev.stop();

    setTimeout(function () {
      //将点击视频进行播放
      var videoContext = wx.createVideoContext(_index)
      videoContext.play();
    }, 500)
  },
  data: {
    onLoad() {
      that = this
    },
    img_list: [],
    photos: [
      '../../img/p1.jpg',
      '../../img/p2.jpg',
      '../../img/p3.jpg',
      '../../img/p4.jpg',
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    navs: [{
      url: '/pages/liucheng/index',
      image: '/img/video.png',
      text: '小程序'
    }, {
      url: '/pages/teacher/teacher',
      image: '/img/video.png',
      text: 'Java'
    }, {
      url: '/pages/xueyuan/index',
      image: '/img/video.png',
      text: 'PHP'
    }, {
      url: '/pages/about/about',
      image: '/img/video.png',
      text: 'C++'
    }]
  },
  //功能导航到点击界面中
  gotopage: function (event) {
    wx.navigateTo({
      url: event.currentTarget.dataset.hi
    })
  },
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '学习中心',
      path: '/pages/index/index',
      success: function (res) {
        // 转发成功
        console.log("转发成功")
      },
      fail: function (res) {
        // 转发失败
        onsole.log("转发失败")
      }
    }
  },
  onLoad: function () {
    that = this;
  },
  onShareAppMessage: function () {
    return {
      title: '你好',
      desc: '欢迎学习!',
      path: '/page/index/index'
    }
  },
  jumpToCourse: function () {
    wx.navigateTo({
      url: "/pages/new_course/course"
    })
  },

  onShow: function () {
    DB.collection('video').get().then(ress => {
      console.log('video_____list', ress.data)

      this.setData({
        list: ress.data.reverse()
      })
    })
    DB.collection('banner').get().then(ress => {
      console.log('img_____list', ress.data)

      this.setData({
        img_list: ress.data
      })
    })
  },
});
